import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/9/25.
///
/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/9/25.
///
/// gongzhonghao biglead
/// github https://github.com/zhaolongs
/// bili https://space.bilibili.com/513480210
/// zhihu https://www.zhihu.com/people/zhao-long-90-89
///
/// csdn https://blog.csdn.net/zl18603543572
/// 西瓜视频 https://www.ixigua.com/home/3662978423
///
///

void main() {
  ///启动根目录
  runApp(MaterialApp(
    home: Example620(),
  ));
}


class Example620 extends StatefulWidget {
  @override
  _Example620State createState() => _Example620State();
}

/// 代码清单 6-7
///lib/code6/example_619_CurvedAnimation.dart
class _Example620State extends State<Example620>
    with SingleTickerProviderStateMixin {
  //动画控制器
  late AnimationController _animationController;
  //文本样式动画
  late Animation<TextStyle> _animation;
  @override
  void initState() {
    super.initState();
    //1、创建动画控制器
    _animationController = AnimationController(
        duration: const Duration(milliseconds: 2000), vsync: this);
    //2、创建曲线动画
    Animation<double> _curvedAnimation =
        CurvedAnimation(parent: _animationController, curve: Curves.bounceIn);
    //3、创建一个 Tween，
    _animation = TextStyleTween(
      begin: const TextStyle(
          color: Colors.blue, fontSize: 14, fontWeight: FontWeight.normal),
      end: const TextStyle(
          color: Colors.deepPurple, fontSize: 24, fontWeight: FontWeight.bold),
    ).animate(_curvedAnimation);
    //----------------------------------------------------
    //添加动画状态监听
    _animation.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        //正向执行完毕后立刻反向执行（倒回去）
        _animationController.reverse();
      } else if (status == AnimationStatus.dismissed) {
        //反向执行完毕后立刻正向执行
        _animationController.forward();
      }
    });

    //添加监听
    _animation.addListener(() {});
    //正向执行
    _animationController.forward();
  }

  @override
  void dispose() {
    //销毁
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text(
          "这是一行Flutter代码",
          style: _animation.value,
        ),
      ),
    );
  }
}
